//定义记分牌
class ScorePanel {
    //用来记录分数和等级
    score: number = 0
    level: number = 1
    //设置变量限制等级
    maxLevel: number;
    //设置升级条件
    upScore: number
    //用来显示分数和等级
    scoreEle: HTMLElement
    levelEle: HTMLElement
    constructor(maxLevel: number = 9, upScore: number = 3) {
        this.scoreEle = document.getElementById('score')!
        this.levelEle = document.getElementById('level')!
        this.maxLevel = maxLevel
        this.upScore = upScore
    }

    //设置加分方法
    addScore() {
        this.score++
        this.scoreEle.innerHTML = `${this.score}`
        //判断分数升级
        if (this.score > 0 && this.score % this.upScore === 0) {
            this.levelUp()
        }
    }
    //设置升级方法
    levelUp() {
        //设置等级最高级
        if (this.level < this.maxLevel) {
            this.level++
            this.levelEle.innerHTML = `${this.level}`
        } else if (this.level === this.maxLevel) {
            this.levelEle.innerHTML = `MAX`
            setTimeout(() => {
                alert('！！！多多大胜利！！！')
                alert('点击重新开始游戏')
                location.reload();
            }, 10);
        }
    }
}



export default ScorePanel